package com.csci;
import java.util.LinkedList;
import java.util.Random;
public class RandomGraph {
	
	final int numVertex;
	float vertexDegreeProbabily;
	int degreeOfConnection;
	
	int totalEdges = 0;
	
	Vertex[] vertex = null;
	
	public RandomGraph(int numVertex, int degreeOfConnection){
		this.numVertex = numVertex;
		this.degreeOfConnection = degreeOfConnection;
		this.vertex = new Vertex[this.numVertex];
		calculateVextexDegreeProbabily();
		
	}


	public float calculateVextexDegreeProbabily() {
		float degreeOfConnectionCastToFloat = (float)degreeOfConnection;
		this.vertexDegreeProbabily = degreeOfConnectionCastToFloat/(numVertex-1);
		return vertexDegreeProbabily;
	}
	
	
	public void initializeVertices() {
		for(int i = 0; i < numVertex; i++){
			vertex[i] = new Vertex(i);
			vertex[i].setEdgeListInt(new LinkedList<Integer>());
		}
		updateEdgeList();
		displayAdjacencyList();
	}
	
	public void updateEdgeList() {
		Random rand = new Random();
		int colNum = 0;
		for(int row = 0; row < numVertex; row++){
			for(int col = colNum; col < numVertex; col++){
				float fRand = rand.nextFloat();
				if(row != col && (fRand <= vertexDegreeProbabily)){
					vertex[row].getEdgeListInt().add(col);
					vertex[col].getEdgeListInt().add(row);
					totalEdges++;
				}
				
			}
			colNum++;
		}
		System.out.println("Total number of edges not verified is " + totalEdges);
	}
	
	public void displayAdjacencyList() {
		int totalEdgesVerified = 0;
		for(int i = 0; i < numVertex; i++){
			int j = 0;
			//System.out.print("The vertex " + vertex[i].getId() + " is connected to: ");
			while(j < vertex[i].getEdgeListInt().size()){
				//System.out.print(vertex[i].getEdgeListInt().get(j)+ ", " );
				totalEdgesVerified++;
				j++;
			}
			System.out.println();
		}
		//System.out.println("The totalEdges is " + totalEdges + " totalEdgesVerified is: "+ totalEdgesVerified/2);
		if(totalEdges == (totalEdgesVerified/2)){
			System.out.println("They match");
		}
		else{
			System.out.println("The DO NOT match");
		}
	}
	
	
}
